package com.yc.dygang;

import org.apache.ibatis.annotations.Insert;

import java.lang.annotation.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

@DemoAnno(value="demo2",nums = 19)
public class Demo2 {
    @DemoAnno(value = "", nums = 1)
    public String  name;

    @DemoAnno(value="11", age = "18", nums= {1, 2})
    public void test(){

    }

    public static void main(String[] args) throws NoSuchFieldException, NoSuchMethodException {
        final Field name = Demo2.class.getDeclaredField("name");
        final DemoAnno annotation = name.getAnnotation(DemoAnno.class);
        System.out.println("annotation.value() = " + annotation.value());

        Demo3 demo3 = new Demo3();

        final Class<?> aClass = demo3.getClass();
        //final Method test = aClass.getMethod("test");
        final DemoAnno annotation1 = aClass.getAnnotation(DemoAnno.class);
        System.out.println("annotation1.value() = " + annotation1.value());

    }
}

class Demo3 extends Demo2{
}

@Target(
        value = {ElementType.METHOD
                ,ElementType.FIELD
                ,ElementType.TYPE}
)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface DemoAnno {
    String value();  // 默认属性
    String age() default "1";
    int[] nums();
}
